#!/bin/bash

# 测试所有三个web服务器的脚本

echo "🚀 Testing unified_api framework with all web servers"
echo "=================================================="

# 设置测试环境变量
export JWT_SECRET="test-secret-key-for-demonstration"

# 测试Actix-web服务器
echo ""
echo "📋 Testing Actix-web server..."
echo "Run: cargo run --example actix_server --features actix,jwt,swagger"
echo "Expected output: Server starting on http://127.0.0.1:8080"
echo ""

# 测试Rocket服务器
echo "📋 Testing Rocket server..."
echo "Run: cargo run --example rocket_server --features rocket,jwt,swagger"
echo "Expected output: Server starting on http://127.0.0.1:8081"
echo ""

# 测试Axum服务器
echo "📋 Testing Axum server..."
echo "Run: cargo run --example axum_server --features axum,jwt,swagger"
echo "Expected output: Server starting on http://127.0.0.1:8082"
echo ""

# API测试命令示例
echo "🧪 API Testing Commands:"
echo "========================"
echo ""
echo "Health Check (no auth required):"
echo "curl -X GET http://localhost:8080/api/health"
echo "curl -X GET http://localhost:8081/api/health"
echo "curl -X GET http://localhost:8082/api/health"
echo ""
echo "Get Users (with auth):"
echo "curl -X GET http://localhost:8080/api/users -H \"Authorization: Bearer valid-jwt-token\""
echo "curl -X GET http://localhost:8081/api/users -H \"Authorization: Bearer valid-jwt-token\""
echo "curl -X GET http://localhost:8082/api/users -H \"Authorization: Bearer valid-jwt-token\""
echo ""
echo "Create User (with auth):"
echo "curl -X POST http://localhost:8080/api/users \\"
echo "  -H \"Content-Type: application/json\" \\"
echo "  -H \"Authorization: Bearer valid-jwt-token\" \\"
echo "  -d '{\"name\":\"Test User\",\"email\":\"test@example.com\"}'"
echo ""
echo "Swagger Documentation:"
echo "curl -X GET http://localhost:8080/api/docs"
echo "curl -X GET http://localhost:8081/api/docs"
echo "curl -X GET http://localhost:8082/api/docs"
echo ""

echo "✅ All servers configured and ready for testing!"
echo "📚 Documentation available at each server's /api/docs endpoint"
echo "🏥 Health checks available at each server's /api/health endpoint"